package com.cn.service.impl;

import com.cn.entity.GenProperty;
import com.cn.service.GenPropertyService;
import com.cn.utlis.FreeMarkerUtils;
import com.cn.utlis.IBase;
import com.cn.vo.GenPropertyVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chenyuncong on 2018/9/17.
 */
@Service
public class GenPropertyServiceImpl extends IBase<GenProperty> implements GenPropertyService {
    @Override
    public void updateGP(GenPropertyVo vo) throws Exception {
        GenProperty g = this.get(vo.getId());
        if(!StringUtils.isEmpty(vo.getPropertyName())){
            g.setPropertyName(vo.getPropertyName());
        }
        if(!StringUtils.isEmpty(vo.getPropertyType())){
            g.setPropertyType(vo.getPropertyType());
        }
        if(!StringUtils.isEmpty(vo.getNotes())){
            g.setNotes(vo.getNotes());
        }
        if(!StringUtils.isEmpty(vo.getWebPropertyName())){
            g.setWebPropertyName(vo.getWebPropertyName());
        }
        if(!StringUtils.isEmpty(vo.getWebPropertyLength())){
            g.setWebPropertyLength(vo.getWebPropertyLength());
        }
        if(!StringUtils.isEmpty(vo.getIsSearch())){
            g.setIsSearch(vo.getIsSearch());
        }
        this.update(g);
    }

    @Override
    public List<GenPropertyVo> getGenPropertyVoList(Long genId) throws Exception {
        String sql ="select "+this.columnStr()+" from gen_property where 1=1 and generate_id=?";
        List<GenPropertyVo> list = this.getList(sql,GenPropertyVo.class,genId);
        list.forEach(x->{
            x.setSpacePropertyName(FreeMarkerUtils.upperCharToUnderLine(x.getPropertyName()));
            x.setHeadBigPropertyName(FreeMarkerUtils.captureName(x.getPropertyName()));
        });
        return list;
    }
}
